<?php
	// set_time_limit(0);
	error_reporting(0);
	ini_set('memory_limit','128M');
	set_time_limit(120);
	date_default_timezone_set('PRC');
	date_default_timezone_set('Asia/Chongqing');

	function sendemail($mailto,$mailtoname,$subject,$body,$attaches = array()) {
	   	require_once ("./includes/phpmail/class.phpmailer.php");
	    $config = array(
	        'SMTP_HOST'   => 'smtp.163.com', //SMTP服务器
	        'SMTP_PORT'   => '465', //SMTP服务器端口
	        'SMTP_USER'   => 'baojiaxt@163.com', //SMTP服务器用户名
	        'SMTP_PASS'   => 'baojia123', //SMTP服务器密码
	        'FROM_EMAIL'  => 'baojiaxt@163.com', //发件人EMAIL
	        'FROM_NAME'   => '报价人', //发件人名称
	        'REPLY_EMAIL' => '', //回复EMAIL（留空则为发件人EMAIL）
	        'REPLY_NAME'  => '', //回复名称（留空则为发件人名称）
	    );


	    $mail   = new PHPMailer();
	    $mail->IsSMTP (); // send via SMTP	
	    $mail->Host =     $config['SMTP_HOST']; // SMTP servers
	    $mail->SMTPAuth = true; // turn on SMTP authentication
	    $mail->Port =     $config['SMTP_PORT']; // SMTP PORT
	    $mail->Mailer =   'smtp';
	    $mail->SMTPSecure = "ssl";  // sets the prefix to the servier
	    $mail->Username = $config['SMTP_USER']; // SMTP username 注意：普通邮件认证不需要加 @域名
	    $mail->Password = $config['SMTP_PASS']; // SMTP password
	    $mail->From =     $config['FROM_EMAIL']; // 发件人邮箱
	    $mail->FromName = $config['FROM_NAME']; // 发件人
	    $mail->CharSet = "utf-8"; // 这里指定字符集！
	    $mail->Encoding = "base64";
	    // $mail->ClearAddresses();	//清楚发送后的用户邮箱
		// $mail->ClearAttachments();  //清楚添加后的附件
	    if ( is_array($mailto) && is_array($mailtoname) ) {
	        for( $j=0; $j<count($mailto); $j++ ){
	            $mail->AddAddress($mailto[$j], $mailtoname[$j]);//收件人邮箱和姓名
	        }
	    }else{
	        $mail->AddAddress($mailto, $mailtoname);//收件人邮箱和姓名
	    }
	    $mail->AddReplyTo( $config['FROM_EMAIL'] , $config['FROM_NAME'] );
	    $mail->Subject =$subject;// 邮件主题
	    $mail->MsgHTML($body);
	    $mail->IsHTML(true); // send as HTML

	    // $mail->WordWrap = 50; // set word wrap 换行字数
	    // $mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件
	    // $mail->AddAttachment("/tmp/image.jpg", "new.jpg");
	    //附件
	    if(count($attaches) > 0) {
	        foreach($attaches as $val) {
	            $mail->AddAttachment($val);
	        }
	    }
	    if(!$mail->Send()) {
	        return array('send'=>false,'info'=>$mail->ErrorInfo);
	    } else {
	        return array('send'=>true,'info'=>'Message sent!');
	    }
	}
?>